<extend name="Public/base" />

<block name="body">
<style>
 .add_record div ul li{
    list-style: none;
    margin-top: 30px;
    margin-bottom: 30px;
    margin-left: -50px;
 }
 .add_record div ul li span{
    line-height: 30px;
    width: 60px;
    /*text-align: right;  */
 }
 .add_record div ul li input{
    width: 250px;height: 30px;
    float: right;
    margin-left: 10px;
    border: solid 1px #ccc;
    border-radius: 3px;
    padding-left: 5px;
    line-height: 26px;
 }
 .add_record div ul li select{
    width: 250px;height: 30px;
    float: right;
 }
 .add_record div ul li input:focus { 
    border-color: #66afe9;
    outline: 0;
    -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, 0.6);
    box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, 0.6);
}
.c_green {
    background-color: #5cb85c !important;
    border-color: #5cb85c !important;
    color: white !important;
}
.c_green:hover {
	background-color: #1da51d !important;
    border-color: #1da51d !important;
}
.table tbody td {
    vertical-align: middle !important;
}
._input {
	
}
._input input {
	
}
.search_name {
	border: solid 1px #ccc;
	padding: 4px 4px 4px 8px; 
	margin-right: 5px; 
	border-radius: 4px;
}
.btn-primary { 
    color: #fff;
    background-color: #337ab7;
    border-color: #2e6da4; 
}
.btn-primary:hover {
	color: #fff; 
	background-color: #286090; 
	border-color: #204d74;
}
.btn-info { 
    color: #fff;
    background-color: #5bc0de;
    border-color: #46b8da; 
}
.btn-info:hover {
	color: #fff; 
	background-color: #39b3d7; 
	border-color: #269abc;
}
.btn-warning { 
    color: #fff;
    background-color: #f0ad4e;
    border-color: #eea236; 
}
.btn-warning:hover {
	color: #fff; 
	background-color: #ec971f; 
	border-color: #d58512;
}
.btn-danger { 
    color: #fff;
    background-color: #d9534f;
    border-color: #d43f3a; 
}
.btn-danger:hover {
	color: #fff; 
	background-color: #c9302c; 
	border-color: #ac2925;
}
 </style>
<!-- 标题栏 -->
<div class="main-title">
    <h2>采购列表</h2>
</div>
<div class="data" style="display: none;">
 
  
 
  
    </div><!-- /.panel-body -->
    <!-- 分页 -->
    <div class="page">
        {$_page}
    </div>
</div><!-- /.panel -->   
</block> 
<block name="script">
<link rel="stylesheet" href="__STATIC__/datetimepicker/css/datetimepicker.css" /> 
<script src="__STATIC__/thinkbox/jquery.thinkbox.js"></script>
<script src="__STATIC__/datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
<script src="__STATIC__/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>   
<script type="text/javascript" src="__JS__/jquery.table2excel.min.js"></script> 
 
<script type="text/javascript">
$(function(){
    //新增按钮
    $("#action_add").click(function(){
        window.location.href = $(this).attr('url');
    });  
    //导出数据
  	var date2time="<?php echo date('Y-m-d');?>";
  	$('#jq2excel').click(function(){
      var myDate = new Date();
      $('.excel').table2excel({
          exclude:".noExl",
          name: "计数录入"+date2time,
          filename: "计数录入"+ date2time,
          exclude_img: true,
          exclude_links: true,
          exclude_inputs: true
      });
  	})
})
</script>

<script type="text/javascript">
	
$('#goback').on('click',function () {
    $('#addshow').hide();
})
//新增财务记录
var _htm =  
    "<form id='_form' name='myform' method='post' role='form'>"+
	    "<div class='add_record'>"+
	        "<div>"+
	            "<ul>"+ 
	                "<li class='c_f'>"+
	                    "<span>时间</span>"+
	                    "<input type='text' class='time' name='li[time]'>"+
	                "</li>"+    
	                "<li class='c_f data_box'>"+
	                    "<span>用户名</span>"+
	                    // "<input type='text' name='li[username]'>"+
	                "</li>"+
	                "<li class='c_f'>"+
	                    "<span>班次</span>"+
	                    "<select name='li[classes]'>"+  
	                      	"<option value='0'>早班</option>"+
	                      	"<option value='1'>晚班</option>"+
	                      	"<option value='2'>上半夜</option>"+
	                      	"<option value='3'>下半夜</option>"+
	                    "</select>"+  
	                "</li>"+ 
	                "<li class='c_f'>"+
	                    "<span>数量</span>"+
	                    "<input type='text' name='li[quantity]'>"+
	                "</li>"+
	                "<li class='c_f data_name'>"+
	                    "<span>名称</span>"+
	                    // "<input type='text' name='li[name]'>"+
	                "</li>"+
	                
	                "<p>"+
	                    "<button class='btn btn-default c_green' id='submit' >确 定</button>"+ 
	                "</p>"+ 
	            "</ul>"+
	        "</div>"+
	    "</div>"+
    "</form>";
$('#add_finance').click(function(){
    //新增记录层
    layer.open({ 
      title: '新增计数录入', 
      title: '新增用户', 
      type: 1,
      skin: 'layui-layer-rim', //加上边框
      area: ['500px', '500px'], //宽高
      content: _htm
    });
    $('.time').datetimepicker({
        format: 'yyyy-mm-dd',
        language:"zh-CN",       
        minView:2,             
        autoclose:true
    });
    $('.data_box span').after( $('.data').html());
    $('.data_name span').after( $('.dataname').html());
});
var boole = true;
$(document).on('click','#submit',function(){
    $('.add_record ul li').each(function(){
        var input = $(this).find('input').val();  
        if(input == ''){
            boole = false;
            layer.msg('请填写完整内容!'); 
            return false;
        }else{
            boole = true;
        }
    });   
    if(boole){  
        $.post("{:U('addfinance')}",$('#_form').serialize(),function(data){
            console.log(data); 
            var d=[];
            d[0] = data.time;
            d[1] = data.username;
            d[2] = data.classes;
            d[3] = data.quantity;
            d[4] = data.name; 
            d[5] = data.unit_price; 
            d[6] = data.total;  
            d[7] = data.id;
            var classes = ['早班','晚班','上半夜','下半夜'],
				num = [0,1,2,3]; 
			for( i=0; i<classes.length; i++ )
			{
				if( d[2] == num[i] )
				{
					d[2] = classes[i];
				}
			}; 
            var url = "/index.php?s=/admin/finance/delfinance/id/",
                targetHtml = addHtml(d,url);  
            if( $.trim($('#add-users').html()) == '' ){  
                $('#add-users').append(targetHtml);
            }else{
                $('#add-users tr:first').before(targetHtml);  
            } 
            $('.add_record ul li input').val('');    
        });  
    } 
    if( $('.odd .dataTables_empty').length != 0 ){ 
        $('.odd .dataTables_empty').parent('.odd').remove(); 
    }   
    return false;
});
function addHtml(data,url){
    var targetHtml =
    "<tr>"+
        "<td>"+data[7]+"</td>"+
        "<td name='classes'>"+data[0]+"</td>"+
        "<td name='username'>"+data[1]+"</td>"+
        "<td name='quantity'>"+data[2]+"</td>"+
        "<td name='clanamesses'>"+data[3]+"</td>"+
        "<td name='time'>"+data[4]+"</td>"+ 
        "<td name='unit_price'>"+data[5]+"</td>"+ 
        "<td name='total'>"+data[6]+"</td>"+  
        "<td class='txt_c'>"+
            "<a class='dis_b del_data'>"+
                "<button class='btn btn-danger ajax-get confirm' url='"+url+data[7]+'.html'+"' target-form='ids'>删除</button>"+
            "</a>"+
        "</td>"+
    "</tr>"; 
    return targetHtml;
};

</script>
 
</block>
